import okhttp3.*;

import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        System.out.println("账户: " + args[0]);
        System.out.println("密码: " + args[1]);
        System.out.println("运营商: " + args[2]);
        System.out.println("-----------------------------");
        String company = null;
        if("liantong".equals(args[2])){
            company = "unicom";
        }else if("yidong".equals(args[2])){
            company = "cmcc";
        }else if("dianxin".equals(args[2])){
            company = "telecom";
        }else if("dankuan".equals(args[2])){
            company = "founder";
        }else if("neiwang".equals(args[2])){
            company = "free";
        }else{
            System.out.println("运营商设置错误，请设置为以下五种之一");
            System.out.println("liantong");
            System.out.println("yidong");
            System.out.println("dianxin");
            System.out.println("dankuan");
            System.out.println("neiwang");
            return;
        }

        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
        RequestBody body = RequestBody.create(mediaType, "DDDDD=,0," + args[0] +"@" + company + "&upass="+ args[1] + "&R1=0&R2=0&R3=0&R6=0&para=00&0MKKey=123456&buttonClicked=&redirect_url=&err_flag=&username=&password=&user=&cmd=&Login=");
        Request request = new Request.Builder()
                .url("http://1.1.1.1:801/eportal/?c=ACSetting&a=Login&protocol=http:&hostname=1.1.1.1&iTermType=1&wlanuserip=10.133.238.184&wlanacip=10.10.9.200&mac=00-00-00-00-00-00&ip=10.133.238.184&enAdvert=0&queryACIP=0&loginMethod=1")
                .method("POST", body)
                .addHeader("Connection", "keep-alive")
                .addHeader("Pragma", "no-cache")
                .addHeader("Cache-Control", "no-cache")
                .addHeader("Upgrade-Insecure-Requests", "1")
                .addHeader("Origin", "http://1.1.1.1")
                .addHeader("Content-Type", "application/x-www-form-urlencoded")
                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36")
                .addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
                .addHeader("Referer", "http://1.1.1.1/")
                .addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
                .build();
        try {
            Response response = client.newCall(request).execute();
            String data = response.body().string();
            if(data.contains("已使用")){
                System.out.println("已登录");
            }else if(data.contains("认证成功页")){
                System.out.println("登录成功");
            }else{
                System.out.println("登陆失败");
            }

        } catch (IOException e) {
            System.out.println("网络异常");
            e.printStackTrace();
        }
    }
}
